package org.automated.realestatemanager.db.services;

import java.util.List;

import org.apache.log4j.Logger;
import org.automated.realestatemanager.db.entity.Agency;
import org.automated.realestatemanager.db.util.HibernateUtility;

public class AgencyService extends CommonService<Agency> {

	private final Logger log = Logger.getLogger(AgencyService.class);

	public AgencyService() {
		super(Agency.class);
	}

	public Agency getAgencyByName(final String name) {
		final List<Agency> result = HibernateUtility.getSession()
				.createQuery("from Agency WHERE name = :p")
				.setString("p", name).list();
		if (result == null)
			return null;
		else if (result.size() == 0)
			return null;
		else if (result.size() == 1)
			return result.get(0);
		else
			throw new RuntimeException(
					"More then 1 phone number found in database : " + name);
	}

}
